import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  ClassSerializerInterceptor,
  UseInterceptors,
  UseGuards,
} from '@nestjs/common';
import { ClassInfoService } from './class-info.service';
import { CreateClassInfoDto } from './dto/create-class-info.dto';
import { UpdateClassInfoDto } from './dto/update-class-info.dto';
import {
  GetClassInfoDto,
  ReturnClassInfoDtoList,
} from './dto/get-class-info.dto';
import {
  ApiBody,
  ApiOperation,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { JwtGuard } from '../guards/jwt.guards';

@Controller('class-info')
@UseGuards(JwtGuard) // 校验token是否通过
@UseInterceptors(ClassSerializerInterceptor)
@ApiTags('班级模块')
export class ClassInfoController {
  constructor(private readonly classInfoService: ClassInfoService) {}

  @Post()
  @ApiOperation({ summary: '班级创建' })
  @ApiBody({ type: CreateClassInfoDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateClassInfoDto,
  })
  create(@Body() createClassInfoDto: CreateClassInfoDto) {
    return this.classInfoService.create(createClassInfoDto);
  }

  @Get()
  @ApiOperation({ summary: '班级列表' })
  @ApiQuery({ type: GetClassInfoDto })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: ReturnClassInfoDtoList,
  })
  findAll(@Query() query: GetClassInfoDto) {
    return this.classInfoService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '班级详情' })
  @ApiQuery({ name: 'id', required: true, description: '班级id' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateClassInfoDto,
  })
  findOne(@Param('id') id: number) {
    return this.classInfoService.findDetail(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '班级更新' })
  @ApiQuery({ name: 'id', required: true, description: '班级id' })
  @ApiBody({ type: UpdateClassInfoDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateClassInfoDto,
  })
  update(
    @Param('id') id: string,
    @Body() updateClassInfoDto: UpdateClassInfoDto,
  ) {
    return this.classInfoService.update(+id, updateClassInfoDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '班级删除' })
  @ApiQuery({ name: 'id', required: true, description: '班级id' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: Object,
  })
  remove(@Param('id') id: number) {
    return this.classInfoService.remove(id);
  }
}
